www.gusucode.com > VC++ douglas道格拉斯算法示例-源码程序 > VC++ douglas道格拉斯算法示例-源码程序/code/douglasView.cpp
//Download by http://www.NewXing.com // douglasView.cpp : implementation of the CDouglasView class // #include "stdafx.h" #include "douglas.h" #include "myAPI.h" #include "douglasDoc.h" #include "douglasView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDouglasView IMPLEMENT_DYNCREATE(CDouglasView, CView) BEGIN_MESSAGE_MAP(CDouglasView, CView) //{{AFX_MSG_MAP(CDouglasView) ON_COMMAND(ID_DOUGLAS, OnDouglas) ON_UPDATE_COMMAND_UI(ID_DOUGLAS, OnUpdateDouglas) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDouglasView construction/destruction CDouglasView::CDouglasView() { // TODO: add construction code here m_douglas=false; } CDouglasView::~CDouglasView() { } BOOL CDouglasView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CDouglasView drawing void CDouglasView::OnDraw(CDC* pDC) { CDouglasDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if(pDoc->m_bIsLoaded) { pDoc->m_douglas->Draw(pDC); if(m_douglas==true) { CUIntArray aPtNum; for(int i=0;i<pDoc->m_douglas->m_LineArray.GetSize();i++) { CMyLine* pLine=pDoc->m_douglas->m_LineArray.GetAt(i); POINT* m_PointList; int nPt=pLine->m_Points.GetSize(); m_PointList = new POINT [nPt]; for(int j=0;j<pLine->m_Points.GetSize();j++) { m_PointList[j].x=pLine->m_Points.GetAt(j).x; m_PointList[j].y=pLine->m_Points.GetAt(j).y; } DouglasPeuckerDataCompress(m_PointList,nPt,aPtNum,100); CPen m_pen; CPen * pPen; m_pen.CreatePen(PS_SOLID,1,RGB(100,100,100)); pPen=pDC->SelectObject(&m_pen); POINT ptstart=m_PointList[aPtNum.GetAt(0)]; pDC->MoveTo(ptstart.x,ptstart.y); for(int m=0;m<aPtNum.GetSize();m++) { POINT pt=m_PointList[aPtNum.GetAt(m)]; pDC->LineTo(pt.x,pt.y); } pDC->SelectObject(pPen); m_pen.DeleteObject(); } } } // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CDouglasView printing BOOL CDouglasView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CDouglasView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CDouglasView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CDouglasView diagnostics #ifdef _DEBUG void CDouglasView::AssertValid() const { CView::AssertValid(); } void CDouglasView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CDouglasDoc* CDouglasView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDouglasDoc))); return (CDouglasDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CDouglasView message handlers void CDouglasView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { // TODO: Add your specialized code here and/or call the base class CDouglasDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CRect rc; GetClientRect(&rc); pDC->SetMapMode(MM_ISOTROPIC); pDC->SetViewportOrg((rc.left+rc.right)/2,(rc.top+rc.bottom)/2); pDC->SetWindowOrg(pDoc->m_WindowOrgX,pDoc->m_WindowOrgY); pDC->SetViewportExt(rc.Width()+50,-rc.Height()+50); pDC->SetWindowExt(pDoc->m_MapSize.cx, pDoc->m_MapSize.cy); CView::OnPrepareDC(pDC, pInfo); } void CDouglasView::OnDouglas() { // TODO: Add your command handler code here m_douglas=true; Invalidate(); } void CDouglasView::OnUpdateDouglas(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here }